package com.duan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.duan.mapper.RoleMapper;
import com.duan.pojo.Role;
import com.duan.service.RoleService;
import com.duan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author db
 * @version 1.0
 * @description RoleServiceImpl
 * @since 2024/2/20
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private UserService userService;
//    @Override
//    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
//    public void deleteRole(Integer roleId) {
//        roleMapper.deleteById(roleId);
//
//        userService.deleteUserByRoleId(roleId);
//    }
//    @Override
//    @Transactional()
//    public void deleteRole(Integer roleId) {
//         roleMapper.deleteById(roleId);
//
//         userService.deleteUserByRoleId(roleId);
//}
    @Override
    @Transactional
    public void deleteRole(Integer roleId) {
        roleMapper.deleteById(roleId);
        Role roleByRoleId = getRoleByRoleId(roleId);

        userService.deleteUserByRoleId(roleId);
    }

    @Override
    public Role getRoleByRoleId(Integer roleId) {
        Role role = roleMapper.selectById(roleId);
        return role;
    }


}
